<template>
  <div class="body">
    <Main pt pb>
      <template slot="main">
        <div class="carousel-box">
          <van-swipe :autoplay="3000">
            <van-swipe-item
              v-for="(item, index) in carousel"
              :key="index"
            >
              <img v-lazy="item.image" @click="zhixinfun(item)" />
            </van-swipe-item>
          </van-swipe>
          <div class="assets-box">
            <van-row>
              <van-col span="8">
                <div class="assets-info-box">
                  <div>总资产</div>
                  <div>{{zhichan.cjf}}</div>
                </div>
              </van-col>
              <van-col span="8">
                <div class="assets-info-box">
                  <div>可用资产</div>
                   <div>{{zhichan.ajf}}</div>
                </div>
              </van-col>
              <van-col span="8">
                <div class="assets-info-box">
                  <div>冻结资产</div>
                   <div>{{zhichan.bjf}}</div>
                </div>
              </van-col>
            </van-row>
          </div>
        </div>

        <div class="content-box">
          <div class="news-box">
            <van-button
              type="danger"
              to="/news/list"
            >最新资讯</van-button>
            <van-button
              type="info"
              to="/guide/index"
            >新手指南</van-button>
          </div>

        </div>
        <div class="news-list-box">
          <van-cell
            :to="'/news/detail?id='+ item.id"
            v-for="(item,inx) in news"
            :key="inx"
          >
            <div class="news-flex">
              <div class="news-banner">
                <img
                  :src="item.thumb"
                  alt=""
                >
              </div>
              <div class="news-info">
                <p class="news-title">
                  {{item.title}}
                </p>

                <p class="news-time">
                  发布时间 {{item.time}}
                </p>
              </div>
            </div>
          </van-cell>
        </div>
      </template>
    </Main>
  </div>
</template>

<script type="text/ecmascript-6">
import { news,user } from "@/api";

export default {
  //接收父级传递的参数
  props: [],
  //监听数据变化
  watch: {},
  data() {
    return {
      carousel: [],
      news: []
    };
  },
  //实例初始化之前触发事件
  beforeCreate() {},
  //实例化之后触发事件
  created() {},
  //实时监控data参数数据变化
  computed: {
    zhichan(){
      return this.$store.getters.zhichans
    }
  },
  //模板组件
  components: {},
  //执行方法
  methods: {
    getList() {
      news.newslist({ page: 1,type:2 }).then(res => {
          if(res.code==1000){
             if(Number(res.count) != 0){
              this.news=[...this.news,...res.result]
             }else{
               this.news=[]
             }
          }
      });
    },
    zhichanFun(){
       this.$store.dispatch("addzhichan")
    },
    zhixinfun(item){
          if(Number(item.contentid)!=0){
            this.$router.push(`/news/detail?id=${item.id}`)
          }
    },
    banners(){
  
      news.banner().then(res=>{
        if(res.code==1000){
          this.carousel=res.result
        }
      })
    }
  },
  mounted() {
    this.getList();
    this.banners()
    this.zhichanFun()
  }
  //路由退出时候调用
  //beforeRouteLeave(to, from, next){next()}
};
</script>

<style scoped lang="less">
.carousel-box {
  position: relative;
  .van-swipe {
    height: 13.5rem;
  }
  img {
    width: 100%;
    z-index: -1;
  }
  .assets-box {
    height: 3.2rem;
    width: 96%;
    text-align: center;
    -moz-box-shadow: 2px 2px 5px #e4e4e4;
    -webkit-box-shadow: 2px 2px 5px #e4e4e4;
    box-shadow: 2px 2px 5px #e4e4e4;
    background-color: #ffffff;
    position: absolute;
    top: 12rem;
    left: 2%;
    border-radius: 0.2rem;
    .assets-info-box {
      height: 3.5rem;

      div:first-child {
        height: 1.5rem;
        font-size: 12px;
        line-height: 1.5rem;
        color: #afafaf;
      }

      div:last-child {
        height: 1.5rem;
        line-height: 1.5rem;
        font-size: 16px;
        color: #323232;
      }
    }
  }
}

.content-box {
  width: 96%;
  margin: auto;
  margin-top: 2.5rem;
  .news-box {
    height: 3.5rem;
    line-height: 3.5rem;

    button {
      width: 45%;
      border-radius: 0.2rem;
    }

    button:first-child {
      float: left;
      -moz-box-shadow: 1px 1px 3px #ff4444;
      -webkit-box-shadow: 1px 1px 3px #ff4444;
      box-shadow: 1px 1px 3px #ff4444;
    }

    button:last-child {
      float: right;
      -moz-box-shadow: 1px 1px 3px #1989fa;
      -webkit-box-shadow: 1px 1px 3px #1989fa;
      box-shadow: 1px 1px 3px #1989fa;
    }
  }
}

.news-list-box {
  margin-bottom: 3.5rem;
  .news-flex {
    display: flex;
  }
  .news-banner {
    height: 4.5rem;
    width: 7rem;
    img {
      width: 100%;
      height: 100%;
      border-radius: 0.2rem;
    }
  }

  .news-info {
    width: 13.5rem;
    margin-left: 1rem;
    .news-title {
      overflow: hidden;
      text-overflow: ellipsis;
      display: -webkit-box;
      -webkit-line-clamp: 2; // 控制多行的行数
      -webkit-box-orient: vertical;
    }

    .news-time {
      margin-top: 0.5rem;
      font-size: 12px;
      color: #afafaf;
    }
  }
}
</style>
